//
//  MainObject.m
//  pa
//
//  Created by HaiJiao Chen on 12-7-28.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MainObject.h"
#import "TicketList.h"
#import "TicketView.h"
#import "nibLoader.h"
#import "CHJAlertView.h"
#import "FilePack.h"
#include "text_def.h"
#import "XMLObject.h"
#import "TimeButton.h"
#import "AddWaterView.h"
#import "AcceptTermsView.h"
#import "KXUIColor.h"
#import "ListControllerBG.h"
#import "KXActionSheet.h"
#import "TextFormatingMini.h"
#import "TicketList.h"
#import "E_PrintView.h"

@interface TicketListController : ListController
@end


@implementation MainObject
@synthesize ticketsDataSource;

@synthesize view;
@synthesize list;
@synthesize bottom;
@synthesize btn_go;
@synthesize term;
@synthesize backButton;
@synthesize ticketView;


- (id)init
{
    self = [super init];
    if (self)
    {
        ticketsDataSource = [[TicketList alloc] init];
        timer = [[KXTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(time) forMode:NSRunLoopCommonModes] retain];
        [ticketsDataSource refresh];
        ticketView = [[nibLoader load:@"Ticket" params:nil] retain];
        [ticketView setupBG];
        
        NSBundle* main = [NSBundle mainBundle];
        [main loadNibNamed:@"MainView" owner:self options:nil];
        
        [[AppDelegate sharedInstance].mainView addSubview:self.view];
        [self.view insertSubview:ticketView atIndex:0];
        ticketView.center = CGPointMake(512, 315);
        
        btn_time = [[TimeButton alloc] initWithFrame:CGRectZero];
        [btn_time addTarget:self action:@selector(time_btn_clicked:) forControlEvents:UIControlEventTouchUpInside];
        times[0] = ticketView.time_left_plant;
        str_time_keys[0] = STR_TIME_LEFT_PLANT;
        c_time_keys[0] = C_TIME_LEFT_PLANT;
        times[1] = ticketView.time_arrived_job;
        str_time_keys[1] = STR_TIME_ARRIVED_JOB;
        c_time_keys[1] = C_TIME_ARRIVED_JOB;
        times[2] = ticketView.time_start_pour;
        str_time_keys[2] = STR_TIME_START_POUR;
        c_time_keys[2] = C_TIME_START_POUR;
        times[3] = ticketView.time_finished_pour;
        str_time_keys[3] = STR_TIME_FINISHED_POUR;
        c_time_keys[3] = C_TIME_FINISHED_POUR;
        times[4] = ticketView.time_left_job;
        str_time_keys[4] = STR_TIME_LEFT_JOB;
        c_time_keys[4] = C_TIME_LEFT_JOB;
        times[5] = ticketView.time_arrived_plant;
        str_time_keys[5] = STR_TIME_ARRIVED_PLANT;
        c_time_keys[5] = C_TIME_ARRIVED_PLANT;
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changed:) name:DataSourceChangeNotification object:nil];
        
        [[AppDelegate sharedInstance] sendHttpRequest:[NSString stringWithFormat:@"getTerm?", ticketView.ticketID] params:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"getTerm", @"type", nil] delegate:self];
    }
    return self;
}

- (void)time
{
    [ticketsDataSource refresh];
}

- (void)dealloc
{
    [backButton release];
    [term release];
    [ticketListController release];
    [ticketsDataSource release];
    [timer invalidate];
    [self.view removeFromSuperview];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [btn_time release];
    [btn_go release];
    [view release];
    [list release];
    [bottom release];
    [timer release];
    [waittingAlertView close];
    [super dealloc];
}

- (void)updateGoButton
{
    NSDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", ticketView.ticketID]];
    if ([[c valueForKey:IS_GONING] boolValue])
    {
        [btn_go setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        int index = [[c valueForKey:CURRENT_TIME_INDEX] intValue];
        if (index == 6)
        {
            [btn_time removeFromSuperview];
        }
        else
        {
            [ticketView.ticketView addSubview:btn_time];
        }
        [btn_go setTitle:[FilePack getStringByID:STR_GO] forState:UIControlStateNormal];
    }
    else if ([c valueForKey:BATCH_WEIGHT])
    {
        [btn_go setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [btn_go setTitle:[FilePack getStringByID:STR_GO] forState:UIControlStateNormal];
    }
    else
    {
        [btn_go setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [btn_time removeFromSuperview];
        [btn_go setTitle:[FilePack getStringByID:STR_GO] forState:UIControlStateNormal];
    }
}


-(IBAction)scheduled_ticket:(id)sender
{
    backButton.hidden = NO;
    ticketListController = [[TicketListController alloc] init];
    [ticketListController setupController:list data:ticketsDataSource reuse:@"ticketList"];
    ListControllerBG* bg = [[ListControllerBG alloc] initWithFrame:CGRectZero];
    [ticketListController setBGWithColor1:[UIColor colorWithARGB:0xFF757779] color2:[UIColor colorWithARGB:0xFFa0a1a2] height:49 bg:bg];
    [bg release];
    ticketListController.delegate = self;
    list.hidden = NO;
    bottom.hidden = NO;
    CGAffineTransform trans = CGAffineTransformMakeScale(0.85, 0.85);
    trans = CGAffineTransformTranslate(trans, 110, -44);
    ticketView.transform = trans;
    ticketView.userInteractionEnabled = NO;
}
-(IBAction)scheduled_ticket_back:(id)sender
{
    backButton.hidden = YES;
    [ticketListController release];
    ticketListController = nil;
    list.hidden = YES;
    bottom.hidden = YES;
    ticketView.transform = CGAffineTransformIdentity;
    ticketView.userInteractionEnabled = YES;
}
-(IBAction)modify_ticket:(id)sender
{
    AddWaterView* v = [nibLoader load:@"AddWater" params:[NSNumber numberWithLongLong:ticketView.ticketID]];
    [[AppDelegate sharedInstance].mainView addSubview:v];
}
-(IBAction)lock:(id)sender
{
    NSArray* arr = ticketsDataSource.data;
    NSDictionary* dic = nil;
    for (NSDictionary* ticket in arr)
    {
        if ([[ticket valueForKey:@"TicketID"] longLongValue] == ticketView.ticketID)
        {
            dic = ticket;
            break;
        }
    }
    NSMutableDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", ticketView.ticketID]];
    
    NSString* time = [NSString stringWithFormat:@"%@", [NSDate dateWithTimeIntervalSinceNow:0]];
    NSString* CustomerName_1 = [dic valueForKey:@"CustomerName_1"];
    NSString* CustomerName_2 = [dic valueForKey:@"CustomerName_2"];
    NSString* CustomerName_3 = [dic valueForKey:@"CustomerName_3"];
    if (CustomerName_1 == nil) CustomerName_1 = @"";
    if (CustomerName_2 == nil) CustomerName_2 = @"";
    if (CustomerName_3 == nil) CustomerName_3 = @"";
    NSString* CustomerName = [NSString stringWithFormat:@"%@\n%@\n%@", CustomerName_1, CustomerName_2, CustomerName_3];
    NSString* order_code = [dic valueForKey:@"OrderNum"];
    NSString* ticket_code = [dic valueForKey:@"Ticket_"];
    NSString* batch_weights = [c valueForKey:BATCH_WEIGHT];
    if ([[c valueForKey:HIDE_BATCH_WEIGHT] intValue] == 1)
    {
        batch_weights = nil;
    }
    
    NSString* print = [NSString stringWithFormat:@"date and time:%@\ncustomer name:%@\norder code:%@\nticket code:%@", time, CustomerName, order_code, ticket_code];
    if (batch_weights) {
        print = [print stringByAppendingFormat:@"\nbatch weights\n:%@", batch_weights];
    }
    NSArray* params = [NSArray arrayWithObjects:
                       print,
                       [NSNumber numberWithLongLong:ticketView.ticketID],
                       nil];
    E_PrintView* v = [nibLoader load:@"E_PrintView" params:params];
    [[AppDelegate sharedInstance].mainView addSubview:v];

    //KXActionSheet* actionSheet = [[KXActionSheet alloc] init];
    //[actionSheet addButtonWithTitle:[FilePack getStringByID:STR_PRINT] code:^(id p1, id p2, id p3) {
    //    NSArray* arr = ticketsDataSource.data;
    //    NSDictionary* dic = nil;
    //    for (NSDictionary* ticket in arr)
    //    {
    //        if ([[ticket valueForKey:@"TicketID"] longLongValue] == ticketView.ticketID)
    //        {
    //            dic = ticket;
    //        }
    //    }
    //    NSMutableDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", ticketView.ticketID]];
    //            
    //    NSString* time = [NSString stringWithFormat:@"%@", [NSDate dateWithTimeIntervalSinceNow:0]];
    //    NSString* ticket_code = [dic valueForKey:@"Ticket_"];
    //    NSString* batch_weights = [c valueForKey:BATCH_WEIGHT];
    //    
    //    NSString* txt = [NSString stringWithFormat:@"date and time:%@\ncustomer name:%@\norder code:%@\nticket code:%@\nbatch weights:%@", time, nil, nil, ticket_code, batch_weights];
    //    
    //    Printer* v = [nibLoader load:@"Printer" params:txt];
    //    
    //    
    //    [[AppDelegate sharedInstance].mainView addSubview:v];
    //    
    //    //TextFormatingMini *textformatingvar = [[TextFormatingMini alloc] initWithNibName:@"TextFormatingMini" bundle:[NSBundle mainBundle]];
    //    //UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:textformatingvar];
    //    //[[navi view] setFrame:CGRectMake(0, 20, 1024, 748)];
    //    //[[[AppDelegate sharedInstance] window] addSubview:[navi view]];
    //    
    //} param:nil];
    //[actionSheet addButtonWithTitle:[FilePack getStringByID:STR_E_MAIL] code:^(id p1, id p2, id p3) {
    //    E_invoce* v = [nibLoader load:@"E_invoce" params:[NSNumber numberWithLongLong:ticketView.ticketID]];
    //    [[AppDelegate sharedInstance].mainView addSubview:v];
    //} param:nil];
    //[actionSheet addButtonWithTitle:[FilePack getStringByID:STR_CANCEL] code:^(id p1, id p2, id p3) {
    //} param:nil];
    //[actionSheet setCancelButtonIndex:2];
    //[actionSheet showInView:view];
    //[actionSheet release];
}
-(IBAction)go:(id)sender
{
    NSDictionary* memoery = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", ticketView.ticketID]];
    
    BOOL canGo = NO;
    for (NSUInteger i = 0; i < ticketsDataSource.data.count; i++)
    {
        NSDictionary* dic = [ticketsDataSource.data objectAtIndex:i];
        long long tid = [[dic valueForKey:@"TicketID"] longLongValue];
        if (tid == ticketView.ticketID)
        {
            NSMutableDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", tid]];
            if ([c valueForKey:BATCH_WEIGHT])
            {
                canGo = YES;
            }
            else if ([[dic valueForKey:DONT_NEED_BW] intValue] == 1)
            {
                canGo = YES;
            }
            break;
        }
    }
    
    if (canGo)
    {
        if ([[memoery valueForKey:IS_GONING] boolValue] == NO)
        {
            NSMutableDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", ticketView.ticketID]];
            [c setValue:[NSNumber numberWithBool:YES] forKey:IS_GONING];
            [c setValue:[NSNumber numberWithInt:0] forKey:CURRENT_TIME_INDEX];
            
            [self updateGoButton];
            
            [ticketView.ticketView addSubview:btn_time];
            btn_time.frame = times[0].frame;
            
            
            //waittingAlertView = [[CHJAlertView alloc] init];
            //[waittingAlertView setLoadingText:[FilePack getStringByID:STR_PLEASE_WAIT] animated:YES];
            //[waittingAlertView show];
            //[waittingAlertView release];
            //
            //[[AppDelegate sharedInstance] sendHttpRequest:[NSString stringWithFormat:@"getBatchWeight?&ticketID=%lld", ticketView.ticketID] params:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithLongLong:ticketView.ticketID] ,@"ticketID", @"go", @"type", nil] delegate:self];
        }
    }
}


-(IBAction)sign_ticket:(id)sender
{
    AcceptTermsView* v = [nibLoader load:@"AcceptTerms" params:[NSNumber numberWithLongLong:ticketView.ticketID]];
    [[AppDelegate sharedInstance].mainView addSubview:v];
}
-(IBAction)submit:(id)sender
{
    [self submitWithDeleteTicket:YES];
}
-(void)submitWithDeleteTicket:(BOOL)bDelete
{
    NSDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", ticketView.ticketID]];
    NSMutableDictionary* upload = [[NSMutableDictionary alloc] initWithCapacity:10];
    [upload setValue:[c valueForKey:C_TIME_LEFT_PLANT] forKey:@"time_left_plant"];
    [upload setValue:[c valueForKey:C_TIME_ARRIVED_JOB] forKey:@"time_arrived_job"];
    [upload setValue:[c valueForKey:C_TIME_START_POUR] forKey:@"time_start_pour"];
    [upload setValue:[c valueForKey:C_TIME_FINISHED_POUR] forKey:@"time_finished_pour"];
    [upload setValue:[c valueForKey:C_TIME_LEFT_JOB] forKey:@"time_left_job"];
    [upload setValue:[c valueForKey:C_TIME_ARRIVED_PLANT] forKey:@"time_arrived_plant"];
    [upload setValue:[c valueForKey:ACCEPT_TERMS] forKey:@"accept_terms"];
    [upload setValue:[c valueForKey:SIGN_NAME] forKey:@"signby"];
    [upload setValue:[c valueForKey:REJECT_NAME] forKey:@"rejectby"];
    [upload setValue:[c valueForKey:REJECT_REASON] forKey:@"rejectreason"];
    [upload setValue:[c valueForKey:DRIVER_NOTE] forKey:@"driver_note"];

    NSMutableArray* emails = [NSMutableArray arrayWithArray:[c valueForKey:EMAILS]];
    [emails addObjectsFromArray:[c valueForKey:CUSTOM_EMAILS]];
    [upload setValue:[emails componentsJoinedByString:@";"] forKey:@"email"];

    NSArray* signature = [c valueForKey:SIGNATURE];
    for (NSUInteger i = 0; i < signature.count; i++)
    {
        [upload setValue:[signature objectAtIndex:i] forKey:[NSString stringWithFormat:@"signature%d", i+1]];
    }
    [upload setValue:[NSNumber numberWithLongLong:ticketView.ticketID] forKey:@"ticketID"];
    
    if ([[upload valueForKey:@"accept_terms"] intValue] == 0 || ([upload valueForKey:@"signature1"] == nil && [upload valueForKey:@"rejectby"] == nil))
    {
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"please accept terms and signature or reject" delegate:nil cancelButtonTitle:@"O K" otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
    else
    {
        waittingAlertView = [[CHJAlertView alloc] init];
        [waittingAlertView setLoadingText:[FilePack getStringByID:STR_PLEASE_WAIT] animated:YES];
        [waittingAlertView show];
        [waittingAlertView release];
        
        [[AppDelegate sharedInstance] postHttpRequest:@"submitTicket" body:upload params:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithLongLong:ticketView.ticketID] ,@"ticketID", @"submit", @"type", [NSNumber numberWithBool:bDelete], @"bDelete", nil] delegate:self multipart:YES];
    }
    [upload release];
}

-(IBAction)logout:(id)sender
{
    [[AppDelegate sharedInstance] logout];
}

- (void)time_btn_clicked:(id)sender
{
    NSDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", ticketView.ticketID]];
    int index = [[c valueForKey:CURRENT_TIME_INDEX] intValue];
    times[index].text = [btn_time titleForState:UIControlStateNormal];
    [c setValue:times[index].text forKey:str_time_keys[index]];
    [c setValue:[NSNumber numberWithLongLong:btn_time.currentTime] forKey:c_time_keys[index]];
    if (index == 5)
    {
        [btn_time removeFromSuperview];
    }
    else
    {
        btn_time.frame = times[index+1].frame;
    }
    [c setValue:[NSNumber numberWithInt:index+1] forKey:CURRENT_TIME_INDEX];
}
- (void)tableView:(UITableView*)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary* dic = [[ticketsDataSource data] objectAtIndex:[indexPath row]];
    [ticketView setTicketID:[[dic valueForKey:@"TicketID"] longLongValue]];
    [self updateGoButton];
    [table reloadData];
}

- (void)chooseTicket
{
    long long tidckID = -1;
    
    for (NSUInteger i = 0; i < ticketsDataSource.data.count; i++)
    {
        NSDictionary* dic = [ticketsDataSource.data objectAtIndex:i];
        long long tid = [[dic valueForKey:@"TicketID"] longLongValue];
        NSMutableDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", tid]];
        if ([[c valueForKey:IS_GONING] boolValue] == YES)
        {
            tidckID = tid;
            break;
        }
    }

    
    if (tidckID == -1)
    {
        for (NSUInteger i = 0; i < ticketsDataSource.data.count; i++)
        {
            NSDictionary* dic = [ticketsDataSource.data objectAtIndex:i];
            long long tid = [[dic valueForKey:@"TicketID"] longLongValue];
            NSMutableDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", tid]];
            if ([c valueForKey:BATCH_WEIGHT])
            {
                tidckID = tid;
                break;
            }
        }
    }
    
    if (tidckID == -1)
    {
        long long ctime = 0x7fffffffffffffff;
        for (NSUInteger i = 0; i < ticketsDataSource.data.count; i++)
        {
            NSDictionary* dic = [ticketsDataSource.data objectAtIndex:i];
            long long t = [[dic valueForKey:@"ctime"] longLongValue];
            if (t < ctime)
            {
                ctime = t;
                tidckID = [[dic valueForKey:@"TicketID"] longLongValue];
            }
        }
    }
    
    if (tidckID > 0)
    {
        ticketView.ticketID = tidckID;
    }
    [self updateGoButton];
}
- (void)changed:(NSNotification*)notification
{
    if ([notification object] == ticketsDataSource)
    {
        [self updateGoButton];
        [self chooseTicket];
        [list reloadData];
    }
}
-(void)requestFinished:(ASIHTTPRequest*)request params:(NSMutableDictionary*)params data:(XMLObject*)_data succ:(BOOL)succ
{
    //if ([[params valueForKey:@"type"] isEqual:@"go"])
    //{
    //    long long ticketID = [[params valueForKey:@"ticketID"] longLongValue];
    //    if ([_data getIntForKey:@"ret" defaultValue:0] == 1)
    //    {
    //        NSMutableDictionary* c = [ticketsDataSource.memoryObject objectForKey:[NSString stringWithFormat:@"%lld", ticketID]];
    //        [c setValue:[NSNumber numberWithBool:YES] forKey:IS_GONING];
    //        [c setValue:[NSNumber numberWithInt:0] forKey:CURRENT_TIME_INDEX];
    //        [c setValue:[[[_data getXMLObjectForKey:@"Ticket"] getXMLObjectForKey:@"Products"] convert2Array] forKey:BATCH_WEIGHT];
    //        ticketView.ticketID = ticketID;
    //        [self updateGoButton];
    //        [waittingAlertView close];
    //        waittingAlertView = nil;
    //        
    //        [ticketView.ticketView addSubview:btn_time];
    //        btn_time.frame = times[0].frame;
    //    }
    //    else
    //    {
    //        [waittingAlertView setTitle:[_data getStringForKey:@"error" defaultValue:[FilePack getStringByID:STR_ERROR_OCCUR]] max_width:160 animated:YES];
    //        [waittingAlertView closeInTime:2];
    //        waittingAlertView = nil;
    //    }
    //}
    //else
    if ([[params valueForKey:@"type"] isEqual:@"submit"])
    {
        if ([_data getIntForKey:@"ret" defaultValue:0] == 1)
        {
            long long ticketID = ticketView.ticketID;
            ticketView.ticketID = 0;
            [waittingAlertView setTitle:[FilePack getStringByID:STR_SUBMIT_SUCCESSFULL] max_width:160 animated:YES];
            [waittingAlertView closeInTime:2];
            waittingAlertView = nil;
            
            if ([[params valueForKey:@"bDelete"] boolValue])
            {
                NSMutableArray* arr = (NSMutableArray*)ticketsDataSource.data;
                for (NSUInteger i = 0; i < arr.count; i++)
                {
                    NSDictionary* dic = [arr objectAtIndex:i];
                    if ([[dic valueForKey:@"TicketID"] longLongValue] == ticketID)
                    {
                        [arr removeObjectAtIndex:i];
                        [ticketsDataSource saveCustomAndNotifyChange];
                        break;
                    }
                }
                [ticketsDataSource.memoryObject removeObjectForKey:[NSString stringWithFormat:@"%lld", ticketID]];
                
                [self updateGoButton];
                [self chooseTicket];
            }
        }
        else
        {
            [waittingAlertView setTitle:[_data getStringForKey:@"error" defaultValue:[FilePack getStringByID:STR_ERROR_OCCUR]] max_width:160 animated:YES];
            [waittingAlertView closeInTime:2];
            waittingAlertView = nil;
        }
    }
    else if ([[params valueForKey:@"type"] isEqual:@"getTerm"])
    {
        if ([_data getIntForKey:@"ret" defaultValue:0] == 1)
        {
            self.term = [_data getStringForKey:@"Term" defaultValue:nil];
        }
    }
}

-(IBAction)showTicket:(id)sender
{
    CGPoint p = CGPointZero;
    p.x = 0;
    [ticketView.scroll setContentOffset:p animated:YES];
}
-(IBAction)showMap:(id)sender
{
    CGPoint p = CGPointZero;
    p.x = ticketView.frame.size.width;
    [ticketView.scroll setContentOffset:p animated:YES];
}

@end


@implementation TicketListController


-(void)createSubView:(UITableViewCell*)cell
{
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 190, 49)];
    [cell.contentView addSubview:label];
    label.backgroundColor = [UIColor clearColor];
    label.tag = 1;
    [label release];
    cell.contentView.backgroundColor = [UIColor clearColor];
}
-(void)setupNewCell:(UITableViewCell*)cell obj:(id<NSObject>)obj indexPath:(NSIndexPath*)indexPath
{
    NSDictionary* dic = (NSDictionary*)obj;
    UILabel* label = (UILabel*)[cell.contentView viewWithTag:1];
    label.text = [dic valueForKey:@"TicketID"];
    if ([[dic valueForKey:@"TicketID"] longLongValue] == [AppDelegate sharedInstance].main.ticketView.ticketID)
    {
        label.textColor = [UIColor redColor];
        label.font = [UIFont boldSystemFontOfSize:17];
    }
    else
    {
        label.textColor = [UIColor blackColor];
        label.font = [UIFont systemFontOfSize:17];
    }
}
- (CGFloat)heightForRowAtIndexPath:(NSIndexPath *)indexPath obj:(id<NSObject>)obj
{
    return 49;
}

@end

